package com.example.demo.day3;

import android.os.Bundle;

import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import com.example.demo.R;
import com.example.demo.day3.adapter.NewsAdapter;
import com.example.demo.day3.bean.NewsBean;

import java.util.ArrayList;
import java.util.List;

public class NewsActivity extends AppCompatActivity {
    private RecyclerView listView;
    private NewsAdapter mNewsAdapter;

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_news);
        listView = findViewById(R.id.rv_news_content);
        listView.setLayoutManager(new LinearLayoutManager(this));


        mNewsAdapter = new NewsAdapter();

        mNewsAdapter.setList(initData());
        listView.setAdapter(mNewsAdapter);
    }


    //这里适用于模拟数据创建的假数据
    private String[] title = new String[]{"我是模拟标题用的",
            "如何看待郑州一骚年扶起倒地老人，垫付医药费却要不回来，老人却说[我良心过得去]?",
            "一个程序员的水平能差到什么程度",
            "啦啦啦啦",
    };
    private int[] cover = new int[]{R.drawable.vateral_10,
            R.drawable.vateral_11,
            R.drawable.vateral_12,
            R.drawable.vateral_13,
            R.drawable.vateral_14,
            R.drawable.vateral_15,
            R.drawable.vateral_16};

    private List<NewsBean> initData() {
        List<NewsBean> list = new ArrayList<>();
        for (int i = 0; i < 30; i++) {
            list.add(new NewsBean()
                    .setTitle(title[i % title.length])
                    .setHot((int) (Math.random() * 1000))
                    .setDrawable(cover[i % cover.length]));
        }
        return list;
    }
}
